<!DOCTYPE html>
<html>
  <head>
      <title>{{ site.title }}</title>
      {{include 'components/import'}}
      <!-- <link rel="stylesheet" href="/stylesheets/bootst/bootstrap.min.css"> -->
      <link rel="stylesheet" href="/stylesheets/defaultstyle.css">
      <style media="screen">
          .area-pop label {
              margin-top: 0;
          }
          #storeType .radio-inline + .radio-inline, .checkbox-inline + .checkbox-inline {
              margin-left: 0;
          }
      </style>
      <script src="/javascripts/validator.min.js"></script>
      <script src="/javascripts/liteuploader.js"></script>
      <script src="/javascripts/promise.min.js"></script>
  </head>
  <body>
      <!-- {{include 'components/site-nav'}} -->
      {{include 'components/header'}}
      <!-- {{ info }} -->
    <div class="list-tab container-fluid" id="StoreTab">
      <!-- <li role="presentation" class=""><a href="#per-base" role="tab" data-toggle="tab" aria-expanded="false">基本信息</a></li> -->
      <li role="presentation" class="active"><a href="#per-pub" role="tab" data-toggle="tab" aria-expanded="true">我的发布</a></li>
      <!-- <li role="presentation" class=""><a href="#per-fav" role="tab" data-toggle="tab" aria-expanded="false">我的收藏</a></li> -->
    </div>

    <div class="container-fluid form-con" id="publish">
      <div class="container more">

        <div class="form-horizontal">
            {{ if info }}
            <div class="form-group">
              <label for="inputEmail3" class="col-sm-3 control-label">信息标题：</label>
              <div class="col-sm-6">
                <div class="input-group">
                  <div class="input-group-btn">
                    <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                        {{ if info.infoType == 'Attorn = '}}
                            转让
                            {{ else }}
                            求租
                        {{ /if}}
                         <span class="caret"></span></button>
                    <ul class="dropdown-menu">
                      <li class="active"><a href="#">转让</a></li>
                      <!-- <li role="separator" class="divider"></li>
                      <li><a href="#">出租</a></li>
                      <li><a href="#">出售</a></li>
                      <li role="separator" class="divider"></li> -->
                      <li><a href="#">求租</a></li>
                      <!-- <li><a href="#">求售</a></li> -->
                    </ul>
                  </div><!-- /btn-group -->
                  <input type="text" class="form-control" id="pubtitle" placeholder="信息标题" value="{{ info.title }}">
                </div>
              </div>
            </div>
            {{ /if }}

          <div class="form-group">
            <label for="storeType" class="col-sm-3 control-label">商铺类型：</label>
            <div class="col-sm-6" id="storeType">
              <label class="checkbox-inline">
                <input type="radio" name="storetype" value="商业街商铺"> 商业街商铺
              </label>
              <label class="checkbox-inline">
                <input type="radio" name="storetype" value="市场类商铺"> 市场类商铺
              </label>
              <label class="checkbox-inline">
                <input type="radio" name="storetype" value="社区商铺"> 社区商铺
              </label>
              <label class="checkbox-inline">
                <input type="radio" name="storetype" value="百货商场、购物中心商铺"> 百货商场、购物中心商铺
              </label>
              <label class="checkbox-inline">
                <input type="radio" name="storetype" value="商务楼、写字楼商铺"> 商务楼、写字楼商铺
              </label>
              <label class="checkbox-inline">
                <input type="radio" name="storetype" value="交通设施商铺"> 交通设施商铺
              </label>
              <label class="checkbox-inline">
                <input type="radio" name="storetype" value="其他"> 其他
              </label>
            </div>
          </div>
          <div class="form-group">
            <label for="inputEmail3" class="col-sm-3 control-label">所在区域：</label>
            <div class="col-sm-6 area-choose">
              {{ if info.infoType == 'Attorn' }}
                  <i class="fa fa-map-marker"></i>
                  <span>{{ info.estate.district }}</span>
                  <span>地铁{{ info.estate.subway }}-{{ info.estate.station }}</span>
                  <span>{{ info.estate.shopArea }}</span>
                  {{ else if info.infoType == 'SeekLease'}}
                  <i class="fa fa-map-marker"></i>
                  <span>{{ info.estate.district[0] }}</span>
                  <span>地铁{{ info.estate.subway[0] }}-{{ info.estate.station[0] }}</span>
                  <span>{{ info.estate.shopArea[0] }}</span>
              {{ /if }}

              <a href="javascript:;" class="btn btn-default" data-toggle="modal" data-target="#area">重新选择</a>
            </div>
          </div>
          <div class="form-group">
            <label for="inputPassword3" class="col-sm-3 control-label">所属行业：</label>
            <div class="col-sm-3">
              <select class="form-control" id="pubcate">
                <option value="选择行业">选择行业</option>
                <option value="酒楼餐饮">酒楼餐饮</option>
                <option value="美容美发">美容美发</option>
                <option value="服饰鞋包">服饰鞋包</option>
                <option value="专柜转让">专柜转让</option>
                <option value="休闲娱乐">休闲娱乐</option>
                <option value="百货超市">百货超市</option>
                <option value="生活服务">生活服务</option>
                <option value="电子通讯">电子通讯</option>
                <option value="汽修美容">汽修美容</option>
                <option value="医药保健">医药保健</option>
                <option value="家居建材">家居建材</option>
                <option value="教育培训">教育培训</option>
                <option value="旅馆宾馆">旅馆宾馆</option>
                <option value="公司广场">公司工厂</option>
                <option value="其他">其他</option>
              </select>
            </div>
            <!-- <div class="col-sm-3">
              <select class="form-control">
                <option>选择子行业</option>
                <option>面包店</option>
                <option>熟食店</option>
                <option>食堂</option>
                <option>餐馆</option>
              </select>
            </div> -->
          </div>
          <div class="form-group">
            <label for="inputEmail3" class="col-sm-3 control-label">商铺地址：</label>
            <!-- <div class="col-sm-3">
              <select class="form-control">
                <option>选择路段</option>
                <option>中山路</option>
                <option>人民东路</option>
                <option>人民中路</option>
                <option>人民西路</option>
                <option>县前东街</option>
                <option>县前西街</option>
                <option>学前街</option>
                <option>解放东路</option>
                <option>解放南路</option>
                <option>解放中路</option>
                <option>勤学路</option>
                <option>南长街</option>
                <option>新生路</option>
                <option>学前东路</option>
                <option>崇宁路</option>
                <option>后西溪</option>
              </select>
            </div> -->
            <div class="col-sm-3">
              <input type="text" class="form-control" id="storelocat" placeholder="地标性说明" value="{{ info.estate.location }}">
            </div>
            <div class="col-sm-6 col-sm-offset-3">
              <span class="tip">地标性说明，如苏宁广场东侧、淮海路与中山南路路口...</span>
            </div>
          </div>
          <div class="form-group">
            <label for="inputEmail3" class="col-xs-4 col-sm-3 control-label">是否空转：</label>
            <div class="col-xs-8 col-sm-6">
              <label class="radio-inline">
                <input name="empty" type="radio" id="isempty" value="1"> 是
              </label>
              <label class="radio-inline">
                <input name="empty" type="radio" id="noempty" value="0"> 否
              </label>
            </div>
          </div>
          <hr/>

          {{ if info.infoType == 'Attorn'}}
              <div class="form-group">
                <label for="inputEmail3" class="col-xs-4 col-sm-3 control-label">商铺面积：</label>
                <div class="col-xs-8 col-sm-3">
                  <div class="input-group">
                        <input type="text" class="form-control" id="pubarea" placeholder="0" value="{{ info.estate.area }}">
                    <span class="input-group-addon" id="sizing-addon2">m<sup>2</sup></span>
                  </div>
                </div>
              </div>
              {{ else }}
              <div class="form-group more-info-seeklease" style="display:block;">
                <label for="more-info-area-size" class="col-xs-4 col-sm-3 control-label">商铺面积范围：</label>
                <div class="col-xs-8 col-sm-3">
                  <div class="input-group">
                    <input type="number" class="form-control" id="more-info-area-size2" placeholder="最小面积" value="{{ info.estate.area.min }}">
                    <span class="input-group-addon">m<sup>2</sup></span>
                  </div>
                </div>
                <div class="col-xs-8 col-sm-3">
                  <div class="input-group">
                    <input type="number" class="form-control" id="more-info-area-size3" placeholder="最大面积" value="{{ info.estate.area.max }}">
                    <span class="input-group-addon">m<sup>2</sup></span>
                  </div>
                </div>
              </div>
          {{ /if}}
          <div class="form-group">
            <label for="inputEmail3" class="col-xs-4 col-sm-3 control-label">商铺租金：</label>
            <div class="col-xs-8 col-sm-3">
              <div class="input-group">
                  {{ if info.infoType == 'Attorn'}}
                      <input id="pubrental" type="text" class="form-control" placeholder="0" value="{{ info.estate.rental }}">
                      {{ else }}
                      <input id="pubrental" type="text" class="form-control" placeholder="0" value="{{ info.estate.rental.max }}">
                  {{ /if }}

                <div class="input-group-btn">
                  <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">元/月
                       <!-- <span class="caret"></span> -->
                  </button>
                  <!-- <ul class="dropdown-menu dropdown-menu-right">
                    <li><a href="#">元/m<sup>2</sup>/天</a></li>
                  </ul> -->
                </div><!-- /btn-group -->
              </div><!-- /input-group -->
            </div>
          </div>


          <div class="form-group">
            <label for="inputEmail3" class="col-xs-4 col-sm-3 control-label">转让费：</label>
            <div class="col-xs-8 col-sm-6 line">
              <label class="checkbox-inline">
                <input name="empty-2" type="checkbox" id="pubtranfer" value="option1"> 面议
              </label>
            </div>
            <div class="col-sm-3 col-sm-offset-3">
              <div class="input-group">
                  {{ if info.infoType == 'Attorn'}}
                      <input type="text" class="form-control" id="pubtranfernum" placeholder="0" value="{{ info.estate.transferFee }}">
                      {{ else if info.infoType == 'SeekLease'}}
                      <input type="text" class="form-control" id="pubtranfernum" placeholder="0" value="{{ info.estate.transferFee.max }}">
                  {{ /if}}

                <span class="input-group-addon" id="sizing-addon2">万元</span>
              </div>
            </div>
            {{ if info.infoType == 'Attorn' }}
            <div class="col-sm-3">
              <div class="input-group">
                <span class="input-group-addon" id="sizing-addon2">±</span>
                <input type="text" class="form-control" id="puboffset" placeholder="0" value="{{ info.estate.offset }}">
                <span class="input-group-addon" id="sizing-addon2">万元</span>
              </div>
            </div>
            {{ /if }}
          </div>

          <div class="form-group">
            <label for="inputPassword3" class="col-sm-3 control-label">详细介绍：</label>
            <div class="col-sm-6">
              <textarea id="pubcontent" class="form-control" rows="8" placeholder="请输入300字以内的文字介绍" >{{ info.content }}</textarea>
            </div>
            {{ if info.infoType == 'Attorn' }}
            <div class="col-sm-6 col-sm-offset-3">
              <ul class="list-inline" id="moreinfoImagesWrap">
                {{ each info.images data }}
                    <li style="background-image:url({{ data }});"><a href="javascript:;"><i class="fa fa-trash-o"></i></a></li>
                {{ /each }}
                <!-- <li style="background-image:url(/images/1.jpg);"><a href="javascript:;"><i class="fa fa-trash-o"></i></a></li>
                <li style="background-image:url(/images/2.jpg);"><a href="javascript:;"><i class="fa fa-trash-o"></i></a></li> -->
                <li class="add">
                  <div class="fileinput fileinput-new" data-provides="fileinput">
                    <span class="btn btn-default btn-file btn-sm"><span class="fileinput-new"><i class="fa fa-plus"></i></span>
                    <input class="fileUpload" id="cpp_image_pics" type="file" name="images" multiple="multiple" v-model="pics.files" accept="/image/png,/image/gif,/image/jpg,/image/jpeg"/></span>
                    <!--<span class="fileinput-filename"></span>
                    <a href="#" class="close fileinput-exists" data-dismiss="fileinput" style="float: none">×</a>-->
                  </div>
                </li>
              </ul>
            </div>
            <div class="col-sm-6 col-sm-offset-3">
              <span class="tip">您可上传最少1张，最多6张图片，尺寸：600*450px，默认第一张为封面图片。</span>
            </div>
            {{ /if }}

          </div>
          <hr/>
          <div class="form-group">
            <label for="inputPassword3" class="col-xs-4 col-sm-3 control-label">您的身份：</label>
            <div class="col-xs-8 col-sm-6" id="contacttype">
              <label class="radio-inline" >
                <input name="identity" type="radio" id="" value="proprietor"> 业主
              </label>
              <label class="radio-inline">
                <input name="identity" type="radio" id="" value="landlord"> 房东
              </label>
              <label class="radio-inline">
                <input name="identity" type="radio" id="" value="intermediary"> 中介
              </label>
            </div>
          </div>
          <div class="form-group">
            <label for="inputEmail3" class="col-xs-4 col-sm-3 control-label">联系方式：</label>
            <div class="col-xs-8 col-sm-6 line">
              <label class="checkbox-inline">
                <input name="contact" type="checkbox" id="inlineCheckbox1" value="option1"> 默认方式
              </label>
            </div>
            <div class="col-sm-3 col-sm-offset-3">
              <div class="input-group">
                <input id="pubname" type="text" class="form-control" placeholder="联系人" value="{{ info.contact.name }}">
                <div class="input-group-btn">
                  <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                      <label id="more-info-select-gender-label">
                          {{ if info.contact.gender == 'male'}}
                              先生
                              {{ else }}
                              女士
                          {{ /if }}
                      </label>
                      <span class="caret"></span></button>
                  <ul class="dropdown-menu dropdown-menu-right">
                    <li>
                        <a href="javascript:moreInfoSelectGender('female')">女士</a>
                    </li>
                    <li>
                        <a href="javascript:moreInfoSelectGender('male')">先生</a>
                    </li>
                  </ul>
                </div><!-- /btn-group -->
              </div><!-- /input-group -->
            </div>
            <div class="col-sm-3">
              <input id="pubphone" type="text" class="form-control" placeholder="手机或固话" value="{{ info.contact.phone}}">
            </div>
          </div>
        </div>

        <div class="main-do">
            <button type="button" class="btn btn-theme" id="postBtn">确认修改</button>
            <button type="submit" class="btn btn-match" onclick="javascript:window.location.href='/perCenter'">返回</button>
        </div>
      </div>
    </div>

    {{include 'components/footer'}}




    <!-- area choose -->
    <div class="modal fade" id="area" tabindex="-1" role="dialog" aria-labelledby="areaLabel">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="myModalLabel"><small>请选择您发布商铺所在区域：</small></h4>
          </div>
          <div class="modal-body area-pop">
            <div class="item">
              <h4>行政区</h4>
              <div class="con" id="areaWrap">

              </div>
            </div>

            <div class="item">
              <h4>地铁线</h4>
              <div class="con" id="subwayWrap">

              </div>
              <h4>站点</h4>
              <div id="subStation">

              </div>
            </div>


            <div class="item">
              <h4>商圈</h4>
              <div class="con" id="areaShopWrap">

              </div>
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            <button type="button" class="btn btn-theme" id="save-area">确认修改</button>
          </div>
        </div>
      </div>
    </div>
    <script>
    var storePublishInfo = {
        step: 1
    };
    var pimages = '{{@ info.images }}'
    if (pimages && pimages != 'undefined') {
        storePublishInfo.images = pimages.split(',');
    }
    storePublishInfo.gender = '{{@ info.contact.gender}}'
    var cityDatas = {
        city: CITY_ID,
        areas: {},
        subways: {}
    };
    var areaWrap = $('#areaWrap');
    var areaShopWrap = $('#areaShopWrap');
    var subwayWrap = $('#subwayWrap');
    var subwayStationWrap = $('#subStation');

    // 修改的信息
    var moreInfoTitle = $('#pubtitle'); // 标题
    var storeType = $('#storeType'); // 商铺类型
    var moreInfoCategory =$('#pubcate'); // 行业信息
    var storelocat = $('#storelocat'); // 标志性说明
    var isempty = $('#isempty'); // 可空转
    var noempty = $('#noempty'); // 不可空转
    var pubarea = $('#pubarea'); // 商铺面积
    var pubrental = $('#pubrental'); // 商铺租金
    var pubtranfer = $('#pubtranfer'); // 可否面议
    var pubtranfernum = $('#pubtranfernum') // 转让费
    var puboffset = $('#puboffset'); // 转让费偏移量
    var moreInfoDesc = $('#pubcontent'); // 详细信息
    var moreInfoContactName = $('#pubname'); // 联系人、
    var moreInfoContactPhone = $('#pubphone') // 电话
    var contacttype = $('#contacttype'); // 联系人类型
    var moreInfoImages = $('#moreinfoImagesWrap'); // 商铺图片列表
    var moreInfoImagesAddLi = moreInfoImages.find('.add'); // 商铺图片添加按钮
    var saveArea = $('#save-area'); // 保存修改后的地址
    // 获取当前城市商圈数据
    function getBusinessData(callback) {
        var sessionCity = '';
        // var sessionCity = sessionStorage.getItem('city-infos');

        if (sessionCity) {
            cityDatas = JSON.parse(sessionCity);

            console.log(cityDatas);

            buildBusinessData();

            callback && callback();
        }
        else {
            $.ajax({
                type: "GET",
                url: SITE_ADDR + "/city/" + cityDatas.city,
                success: function (data, textStatus) {
                    console.log(data);

                    cityDatas.areas = data.areas;
                    cityDatas.subways = data.subways;

                    sessionStorage.setItem('city-infos', JSON.stringify(data));

                    buildBusinessData();

                    callback && callback();
                }
            });
        }
    }
    getBusinessData();
    // 根据行政区数据创建html
    function buildAreaDataHTML(area, areaIndex, areaShop) {
        var areaHtmlStr = [];

        cityDatas.areas.forEach(function (item, idx) {
            if (area && area == item.name) {
                areaHtmlStr.push('<label class="radio-inline"><input type="radio" name="areaRadio" checked="checked" data-val="'+item.name+'" value="' + idx + '">' + item.name + '</label>');
            }
            else {
                areaHtmlStr.push('<label class="radio-inline"><input type="radio" name="areaRadio" data-val="'+item.name+'" value="' + idx + '">' + item.name + '</label>');
            }
        });

        areaWrap.html(areaHtmlStr.join(''));
        areaShopWrap.html('').hide();

        if (area && cityDatas.areas[areaIndex]) {
            buildShopDataHTML(areaIndex, areaShop);
        }
    }

    // 根据商圈数据创建html
    function buildShopDataHTML(areaIndex, areaShop) {
        if ('全城' == cityDatas.areas[areaIndex].name) {
            areaShopWrap.html('').hide();
            return;
        }

        var shopAreas = cityDatas.areas[areaIndex].shopAreas;

        var shopStr = [];

        shopAreas.forEach(function(item, index) {
            if (areaShop && areaShop == item.name) {
                shopStr.push('<label class="radio-inline"><input type="radio" name="areaShopRadio" data-val="'+item.name+'" checked="checked" value="' + item.name + '">' + item.name + '</label>');
            }
            else {
                shopStr.push('<label class="radio-inline"><input type="radio" name="areaShopRadio" data-val="'+item.name+'" value="' + item.name + '">' + item.name + '</label>');
            }
        });

        areaShopWrap.html(shopStr.join('')).show();
    }

    // 根据地铁数据创建html
    function buildSubwayDataHTML(subway, subwayIndex, subwayStation) {
        var subwayHtmlStr = [];

        cityDatas.subways.forEach(function (item, idx) {
            if (subway && subway == item.name) {
                subwayHtmlStr.push('<label class="radio-inline"><input type="radio" name="subwayRadio" data-val="'+item.name+'" checked="checked" value="' + idx + '">' + item.name + '</label>');
            }
            else {
                subwayHtmlStr.push('<label class="radio-inline"><input type="radio" data-val="'+item.name+'" name="subwayRadio" value="' + idx + '">' + item.name + '</label>');
            }
        });

        subwayWrap.html(subwayHtmlStr.join(''));
        subwayStationWrap.html('').hide();

        if (subway && cityDatas.subways[subwayIndex]) {
            buildStationDataHTML(subwayIndex, subwayStation);
        }
    }

    // 更具地铁线路创建站点html
    function buildStationDataHTML(subwayIndex, station) {
        var subwayStations = cityDatas.subways[subwayIndex].stations;

        var stationsStr = [];

        subwayStations.forEach( function(item, index) {
            if (station && station == item) {
                stationsStr.push('<label class="radio-inline"><input type="radio" data-val="'+item+'" name="subwayStationRadio" checked="checked" value="' + item + '">' + item + '</label>');
            }
            else {
                stationsStr.push('<label class="radio-inline"><input type="radio" data-val="'+item+'" name="subwayStationRadio" value="' + item + '">' + item + '</label>');
            }
        });

        subwayStationWrap.html(stationsStr.join('')).show();
    }
    // 创建区域选择框
    function buildBusinessData() {
        // 行政区
        if (cityDatas && cityDatas.areas && cityDatas.areas.length > 0) {
            buildAreaDataHTML();

            areaWrap.on('change', 'input[name=areaRadio]', function () {
                var areaIndex = $('input[name=areaRadio]:checked').val();
                console.log('checked radio: ', areaIndex);

                storePublishInfo.area = cityDatas.areas[areaIndex].name;
                storePublishInfo.areaIndex = areaIndex;
                storePublishInfo.areaShop = '';

                buildShopDataHTML(areaIndex);
            });

            areaShopWrap.on('change', 'input[name=areaShopRadio]', function () {
                var areaShopName = $('input[name=areaShopRadio]:checked').val();

                storePublishInfo.areaShop = areaShopName;
            });
        }
        else {
            bootbox.alert('商圈数据获取失败，请稍后再尝试');
        }

        // 地铁线
        if (cityDatas && cityDatas.subways && cityDatas.subways.length > 0) {
            buildSubwayDataHTML();

            subwayWrap.on('change', 'input[name=subwayRadio]', function () {
                var subwayIndex = $('input[name=subwayRadio]:checked').val();
                console.log('checked radio: ', subwayIndex);

                storePublishInfo.subway = cityDatas.subways[subwayIndex].name;
                storePublishInfo.subwayIndex = subwayIndex;
                storePublishInfo.subwayStation = '';

                buildStationDataHTML(subwayIndex);
            });

            subwayStationWrap.on('change', 'input[name=subwayStationRadio]', function () {
                var stationName = $('input[name=subwayStationRadio]:checked').val();

                storePublishInfo.subwayStation = stationName;
            });
        }
    }
    var subJson = {
        infoSource: 'PERSONAL',  // 页面上提交的应该都是会员
        estateType : "Store", // 暂时都是商铺
        user: userName,
        isDeleted : false,
        isPreference : false,
        estate: {

        }, // 商铺详情
        contact: {}, // 联系方式

        // 以下待定
        level: 0,
        site: SITE_ID,
        tags: []
    }
    var category = '{{@ info.category }}';
    var estatetype = '{{@ info.estate.type }}';
    var pubType = '{{@ info.infoType}}';

    if ( category ) {
        moreInfoCategory.find('option[value='+category+']').attr('selected',true);
    }
    if ( estatetype ) {
        storeType.find('input[value='+estatetype+']').attr('checked',true);
    }
    if ( 'false' == '{{@ info.estate.canEmptyAttorn }}') {
        $('#isempty').attr('checked',true);
    } else {
        $('#noempty').attr('checked',true);
    }
    var identity = '{{@ info.contact.identity }}';
    if ( identity ) {
        contacttype.find('input[value='+identity+']').attr('checked',true);
    }
    var pid = '{{@ info._id}}';
    // function getData() {
    //     subJson['_id'] = '{{@ info._id}}';
    //     subJson['title'] = pubTitle.val();
    //     subJson['category'] = pubcate.val();
    //     subJson.estate['type'] = storeType.find('input[name=storetype]:checked').val();
    //     // console.log(storeType.find('input').attr('checked',true));
    //     subJson.estate['location'] = storelocat.val();
    //     subJson.estate['canEmptyAttorn'] = $('input[name=empty]:checked').val() == 1?true:false;
    //     if (pubType == 'Attorn') {
    //         subJson.estate['area'] = pubarea.val();
    //     }
    //     console.log(subJson)
    // }
    var moreInfoAreaSize2 = $('#more-info-area-size2');
    var moreInfoAreaSize3 = $('#more-info-area-size3');
    // 根据填写的详细信息拼接信息发布参数
    var submitJson = {
        infoSource: 'PERSONAL',  // 页面上提交的应该都是会员
        infoType: pubType,
        estateType : "Store", // 暂时都是商铺
        user: userName,
        isDeleted : false,
        isPreference : false, // 腾铺优选
        isTraded : true, // 可交换的
        estate: {

        }, // 商铺详情
        contact: {}, // 联系方式

        // 以下待定
        level: 0,
        site: SITE_ID,
        tags: []
    };
    function buildInfoSubmitData() {

        submitJson['title'] = moreInfoTitle.val(); // 标题
        submitJson.estate['type'] = storeType.find('input[name=storetype]:checked').val(); // 商铺类型
        submitJson['category'] = moreInfoCategory.val();
        submitJson.contact['identity'] = contacttype.find('input[name=identity]:checked').val();
        submitJson.contact['name'] = moreInfoContactName.val();
        submitJson.contact['phone'] = moreInfoContactPhone.val();
        submitJson.contact['gender'] = storePublishInfo.gender;
        submitJson['content'] = moreInfoDesc.val();
        if ( pubType == 'Attorn') {
            submitJson['images'] = storePublishInfo.images;
            submitJson.estate['type'] = storeType.find('input[name=storetype]:checked').val(); // 商铺类型
            submitJson.estate['transferFee'] = parseInt(pubtranfernum.val());
            submitJson.estate['offset'] = parseInt(puboffset.val());
            submitJson.estate['area'] = parseInt(pubarea.val());
            submitJson.estate['rental'] = parseInt(pubrental.val());
            // submitJson.estate['propertyFee'] = moreInfoPropertyFee.val(); // 物业费
            //

            // submitJson.estate['district'] = storePublishInfo.area;
            // submitJson.estate['shopArea'] = storePublishInfo.areaShop;
            // submitJson.estate['subway'] = storePublishInfo.subway;
            // submitJson.estate['station'] = storePublishInfo.subwayStation;
        }
        else {
            // 求租的商铺类型值是数组
            submitJson.estate['type'] = [storeType.find('input[name=storetype]:checked').val()];
            submitJson.estate['transferFee'] = {min: 0, max: pubtranfernum.val()*1};
            submitJson.estate['area'] = {min: moreInfoAreaSize2.val()*1, max: moreInfoAreaSize3.val()*1};
            submitJson.estate['rental'] = {min:0, max: pubrental.val()*1};

            // submitJson.estate['district'] = [storePublishInfo.area];
            // submitJson.estate['shopArea'] = [storePublishInfo.areaShop];
            // submitJson.estate['subway'] = [storePublishInfo.subway];
            // submitJson.estate['station'] = [storePublishInfo.subwayStation];
        }


        var areaWrapVal = areaWrap.find('input:checked').data('val');
        var areaShopWrapVal = areaShopWrap.find('input:checked').data('val');
        var subwayWrapVal = subwayWrap.find('input:checked').data('val');
        var subwayStationWrapVal = subwayStationWrap.find('input:checked').data('val');

            if ( pubType == 'Attorn') {
                submitJson.estate['district'] = areaWrapVal?areaWrapVal:'{{@ info.estate.district}}';
                submitJson.estate['shopArea'] = areaShopWrapVal?areaShopWrapVal:'{{@ info.estate.shopArea}}';
                submitJson.estate['subway'] = subwayWrapVal?subwayWrapVal:'{{@ info.estate.subway}}' ;
                submitJson.estate['station'] = subwayStationWrapVal?subwayStationWrapVal:'{{@ info.estate.station}}';
            }
            else {
                submitJson.estate['district'] = areaWrapVal?[areaWrapVal]:'{{@ info.estate.district}}';
                submitJson.estate['shopArea'] = areaShopWrapVal?[areaShopWrapVal]:'{{@ info.estate.shopArea}}';
                submitJson.estate['subway'] = subwayWrapVal?[subwayWrapVal]:'{{@ info.estate.subway}}';
                submitJson.estate['station'] = subwayStationWrapVal?[subwayStationWrapVal]:'{{@ info.estate.station}}';
            }
    }
    // 更多信息里选择性别
    var genderLabel = $('#more-info-select-gender-label');
    function moreInfoSelectGender(gender) {
        console.log('gender: ', gender);
        if ('female' == gender) {
            genderLabel.text('女士');
            storePublishInfo.gender = 'female';
        }
        else {
            genderLabel.text('先生');
            storePublishInfo.gender = 'male';
        }
    }
    window.moreInfoSelectGender = moreInfoSelectGender;


    $('#postBtn').on('click',function(){
        // getData();
        buildInfoSubmitData()
        $.ajax({
            type: "put",
            contentType: "application/json",
            url: SITE_ADDR + "/info/"+pid+"",
            data: JSON.stringify(submitJson),
            success: function (data, textStatus) {
                if (data.ok) {
                    bootbox.alert('修改成功');
                }
                else {
                    bootbox.alert('没发布成功');
                }
            },
            complete: function (XMLHttpRequest, textStatus) {
                submiting = false;
            }
        });
    });

    // --------------------------图片上传--------------------------
    // 限制图片宽高为: 600 * 450
    function enforceWidthHeight(file) {
        return new Promise(function (resolve) {
            var reader = new FileReader();

            reader.onload = function (evt) {
                var image = new Image();

                image.onload = function () {
                    var error = (this.width != 600 || this.height !=450) ?
                        "宽高错误，需要为 600px * 450px" : null;
                    resolve(error);
                };

                image.src = evt.target.result;
            };

            reader.readAsDataURL(file);
        });
    }
    // 渲染上传成功的图片至页面上
    function renderUploadImages(imgSrc) {
        var imgLiHtmlStr = '<li data="' + imgSrc + '" style="background-image:url(' + imgSrc + ');"><a href="javascript:;"><i class="fa fa-trash-o"></i></a></li>';

        $(imgLiHtmlStr).insertBefore(moreInfoImagesAddLi);
    }
    // 图片上传
    $(".fileUpload").liteUploader({
        script: SITE_ADDR + "/upload"
        ,singleFileUploads: true
        // , validators: [enforceWidthHeight] // 宽高限制
    })
    .on("lu:errors", function (e, errors) {
        console.log(errors);
        if (errors && errors.length > 0) {
            var errStr = '上传图片[' + errors[0].name + ']错误：' + errors[0].errors.join(',');
            bootbox.alert(errStr);
        }
    })
    .on("lu:success", function (e, response) {
        console.log(response);
        var response = JSON.parse(response);
        if (response && response.ops && response.ops.length > 0 && response.ops[0].path) {
            if (!storePublishInfo.images) {
                storePublishInfo.images = [];
            }
            storePublishInfo.images.push(response.ops[0].path);

            renderUploadImages(response.ops[0].path);

            if (storePublishInfo.images.length > 6) {
                bootbox.alert('最多上传 6 张图片，请删掉一些图片。');
            }
        }
        else {
            bootbox.alert('图片上传失败，请稍后再试或联系管理员。');
        }
    });

    $(".fileUpload").change(function () {
        $(this).data("liteUploader").startUpload();
    });

    // 删除上传图片
    moreInfoImages.on('click', 'li a', function (e) {
        var theLi = $(this).parent();
        var theSrc = theLi.attr('data');
        console.log(theSrc);

        theLi.remove();
        if (storePublishInfo.images && storePublishInfo.images.indexOf(theSrc) > -1) {
            storePublishInfo.images.splice(storePublishInfo.images.indexOf(theSrc), 1);
        }

        console.log('newStorePublishInfo: ');
        console.log(storePublishInfo);
    });
    saveArea.on('click',function(){
        var areaWrapVal = areaWrap.find('input:checked').data('val');
        var areaShopWrapVal = areaShopWrap.find('input:checked').data('val');
        var subwayWrapVal = subwayWrap.find('input:checked').data('val');
        var subwayStationWrapVal = subwayStationWrap.find('input:checked').data('val');
        if (areaWrapVal && areaShopWrapVal && subwayWrapVal && subwayStationWrapVal) {
            if ( pubType == 'Attorn') {
                submitJson.estate['district'] = areaWrapVal?areaWrapVal:'{{@ info.estate.district}}';
                submitJson.estate['shopArea'] = areaShopWrapVal?areaShopWrapVal:'{{@ info.estate.shopArea}}';
                submitJson.estate['subway'] = subwayWrapVal?subwayWrapVal:'{{@ info.estate.subway}}' ;
                submitJson.estate['station'] = subwayStationWrapVal?subwayStationWrapVal:'{{@ info.estate.station}}';
            }
            else {
                submitJson.estate['district'] = areaWrapVal?[areaWrapVal]:'{{@ info.estate.district}}';
                submitJson.estate['shopArea'] = areaShopWrapVal?[areaShopWrapVal]:'{{@ info.estate.shopArea}}';
                submitJson.estate['subway'] = subwayWrapVal?[subwayWrapVal]:'{{@ info.estate.subway}}';
                submitJson.estate['station'] = subwayStationWrapVal?[subwayStationWrapVal]:'{{@ info.estate.station}}';
            }
            bootbox.alert({
                size: 'smal',
                message: "修改完成"
            });
        }
        else {
            bootbox.alert({
                size: 'smal',
                message: "还有信息未填写"
            });
        }
        console.log(submitJson)
    })
    </script>
  </body>
</html>
